#include<bits/stdc++.h>
#define int long long
#define N 5005
using namespace std;
int n;
int a[N];
int l[N],r[N];
int f[N][N];
const int mod=998244353;
signed main(){
    freopen("after.in","r",stdin);
    freopen("after.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++){
        l[i]=i;
        while(l[i]>1&&a[l[i]-1]<a[i]) l[i]--;
        r[i]=i;
        while(r[i]<n&&a[r[i]+1]<a[i]) r[i]++;
    }
    f[0][0]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++) f[i][j]=f[i-1][j];
        for(int j=l[i],s=0;j<=r[i];j++){
            s=(s+f[i-1][j-1])%mod;
            f[i][j]=(f[i][j]+s)%mod;
        }
    }
    printf("%lld",f[n][n]);
    return 0;
}